import 'dart:async';

import 'package:flutter/material.dart';

class MyDialog extends Dialog {
  String title;
  String content;
  MyDialog({this.title = "提示", this.content = "内容"});

  //定时器
  _showTimer(context) {
    var timer;
    timer = Timer.periodic(Duration(milliseconds: 3000), (t) {
      print("关闭");
      Navigator.pop(context);
      t.cancel();
    });
  }

  @override
  Widget build(BuildContext context) {
    _showTimer(context);
    // TODO: implement build
    return Material(
      type: MaterialType.transparency,
      child: Center(
          child: Container(
        height: 300,
        width: 300,
        color: Colors.white,
        child: Column(
          children: [
            Padding(
              padding: EdgeInsets.all(20),
              child: Stack(
                children: [
                  Align(
                    alignment: Alignment.center,
                    child: Text(this.title),
                  ),
                  Align(
                    alignment: Alignment.topRight,
                    child: InkWell(
                      child: Icon(Icons.close),
                      onTap: () {
                        Navigator.pop(context);
                      },
                    ),
                  ),
                ],
              ),
            ),
            Divider(),
            Container(
              width: double.infinity,
              margin: EdgeInsets.fromLTRB(10, 0, 10, 0),
              child: Text(
                this.content,
                textAlign: TextAlign.left,
              ),
            )
          ],
        ),
      )),
    );
  }
}
